Add garbage collection to SyncOPFSFileSystem to prevent unbounded disk growth#4
Open
MillanWangGadget wants to merge 1 commit into
Open
Add garbage collection to SyncOPFSFileSystem to prevent unbounded disk growth#4MillanWangGadget wants to merge 1 commit into
MillanWangGadget wants to merge 1 commit into
Conversation
…k growth
The arena file previously only grew and never shrank. When files were
overwritten or deleted, old pages were added to the free list but the
underlying OPFS file retained its full size, causing massive disk usage
over time.
- Auto-reclaim trailing free pages after every free (shrinkArenaTrailingFreeSpace)
- Add gc() for full compaction/defragmentation
- Add getStats() for monitoring arena usage
- Add tests proving sequential edits don't grow storage disproportionately
4b99f7a to
825a6eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SyncOPFSFileSystem's arena file only ever grew — overwritingor deleting files freed pages internally but never truncated the backing OPFS
file, causing unbounded disk usage in long-lived sessions.
pages at the end of the arena are now truncated immediately (with a 1 MiB
floor to avoid thrashing).
gc()method relocates all live file datacontiguously and truncates, eliminating internal fragmentation.
getStats()returnsarenaBytes,allocatedBytes,freeBytes, andfreeFragmentsfor monitoring.